package com.bw.ppjokeplay.mvvm.viewmodel

import com.bw.ppjokeplay.common.entity.BaseEntity
import com.bw.ppjokeplay.common.mvvm.adapter.HomeListAdapter
import com.bw.ppjokeplay.common.mvvm.viewmodel.BaseViewModel
import com.bw.ppjokeplay.mvvm.model.HomeListModel
import com.bw.ppjokeplay.mvvm.model.entity.HomeFeedEntity
import io.reactivex.Scheduler
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

class HomeListViewModel : BaseViewModel<HomeListModel>() {

    private var pageCount : Int = 12
    private val feedId = 0;
    private val feedType = "all"
    private var userId = 0
    val adapter : HomeListAdapter = HomeListAdapter()

    override fun result(t: BaseEntity) {
        if (t is HomeFeedEntity){
            val homeFeedEntity : HomeFeedEntity = t as HomeFeedEntity
            adapter.setNewInstance(homeFeedEntity.data!!.data)
        }
    }

    override fun initData() {
        m.requestHomeList(feedId,feedType,pageCount,userId)!!.
        subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this)
    }
}